package net.sx.minemodule.mvp.presenters;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.homegoods.area.model.SubModelList;
import com.kedll.library.mvp.AbstractRefreshPresenter;
import com.kedll.library.mvp.RefreshingView;

import net.sx.minemodule.MineApiUtils;
import net.sx.minemodule.R;
import net.sx.minemodule.mvp.model.BrokerageListModel;
import net.sx.minemodule.mvp.model.CommissionListModel;
import net.sx.minemodule.mvp.model.HistoryBrokerageModel;
import net.sx.minemodule.mvp.model.HistoryCommissionModel;
import net.sx.minemodule.mvp.model.HistoryMedalModel;
import net.sx.minemodule.mvp.model.MineMedalListModel;

import java.util.List;

/**
 * add shibo.zheng
 * 19/06/17
 * 记录详情presenter
 */

public class MineRecordInfoPresenter extends AbstractRefreshPresenter {
    private static final String TAG = "MineRecordInfoPreTag";
    private String recordInfoType;

    public MineRecordInfoPresenter(RefreshingView mView) {
        super(mView);
        emptyItem.setResId(R.mipmap.mine_no_message);
        emptyItem.setContent("暂无消息");
    }

    @Override
    protected void fetchData(boolean isLoadMore) {
        Log.d(TAG, "fetchData: recordInfoType == " + recordInfoType);
        if ("medalHistory".equals(recordInfoType)) {                //历史奖牌记录
            MineApiUtils.getHistoryMedal(1, 10, subModelList -> {
                List<HistoryMedalModel> historyMedalModels = JSON.parseArray(subModelList.getItems(), HistoryMedalModel.class);
                MineRecordInfoPresenter.this.parserData(isLoadMore, historyMedalModels);
            }, throwable -> {});
        } else if ("medalInfo".equals(recordInfoType)) {            //奖牌明细
            MineApiUtils.getMedalList(1, 10, subModelList -> {
                Log.d(TAG, "accept: subModelList == " + JSON.toJSONString(subModelList));
                List<MineMedalListModel> medalListModels = JSON.parseArray(subModelList.getItems(), MineMedalListModel.class);
                parserData(isLoadMore, medalListModels);
            }, throwable -> {});
        } else if ("HistoryCommission".equals(recordInfoType)) {   //历史提成记录
            MineApiUtils.getHistoryCommission(1, 10, subModelList -> {
                List<HistoryCommissionModel> models = JSON.parseArray(subModelList.getItems(), HistoryCommissionModel.class);
                parserData(isLoadMore, models);
            }, throwable -> {});
        } else if ("CommissionList".equals(recordInfoType)) {       //提成明细
            MineApiUtils.getCommissionList(1, 10, subModelList -> {
                List<CommissionListModel> models = JSON.parseArray(subModelList.getItems(), CommissionListModel.class);
                parserData(isLoadMore, models);
            }, throwable -> {});
        } else if ("brokerageHistory".equals(recordInfoType)) {     //佣金历史记录
            MineApiUtils.getHistoryBrokerage(1, 10, s -> {
                List<HistoryBrokerageModel> models = JSON.parseArray(s.getItems(), HistoryBrokerageModel.class);
                parserData(isLoadMore, models);
            }, throwable -> {});
        } else if ("brokerageList".equals(recordInfoType)) {        //佣金明细
            MineApiUtils.getBrokerageList(1, 10, subModelList -> {
                List<BrokerageListModel> models = JSON.parseArray(subModelList.getItems(), BrokerageListModel.class);
                parserData(isLoadMore, models);
            }, throwable -> {});
        }
    }

    /**
     * 设置当前界面的type，根据teyp区分界面
     * @param type
     */
    public void setRecordInfoType(String type) {
        this.recordInfoType = type;
    }
}
